package repository

import (
    "gorm.io/gorm"
    "generator-tool/models"
)

type ShGoodRepository struct {
    DB *gorm.DB
}

func NewShGoodRepository(db *gorm.DB) *ShGoodRepository {
    return &ShGoodRepository{DB: db}
}

func (r *ShGoodRepository) CreateShGood(ShGood *models.ShGood) error {
    return r.DB.Create(ShGood).Error
}

func (r *ShGoodRepository) GetAllShGoods() ([]models.ShGood, error) {
    var ShGoods []models.ShGood
    err := r.DB.Find(&ShGoods).Error
    return ShGoods, err
}

func (r *ShGoodRepository) GetShGoodByID(id uint) (*models.ShGood, error) {
    var ShGood models.ShGood
    err := r.DB.First(&ShGood, id).Error
    if err != nil {
        return nil, err
    }
    return &ShGood, nil
}

func (r *ShGoodRepository) UpdateShGood(ShGood *models.ShGood) error {
    return r.DB.Save(ShGood).Error
}

func (r *ShGoodRepository) DeleteShGood(id uint) error {
    return r.DB.Delete(&models.ShGood{}, id).Error
}